/*
 * Created by SharpDevelop.
 * User: Guy Fomi
 * Date: 2/5/2011
 * Time: 10:11 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Web.Script.Serialization;
using System.Diagnostics;
using HtmlAgilityPack;
using TomatoSynchronizer.Store;
using TomatoSynchronizer.Forms;
using FileSystemDatabase;

namespace TomatoSynchronizer
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		private HtmlWeb client;
		
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			client = new HtmlWeb();
			LoadSites();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		private void LoadSites()
		{
			JsonDatabase db = new JsonDatabase("sites");
			Site[] sites  = db.Read<Site>();
			
			comboBox1.Items.Clear();
			
			foreach(Site site in sites)
			{
				comboBox1.Items.Add(site.Name);
			}
		}
		
		void Button1Click(object sender, EventArgs e)
		{
			lstConsole.Items.Clear();
			Site src = new Site("Appui Cameroun",txtSite.Text,txtUser.Text,txtPass.Text);
			lstConsole.Items.Add("Ouverture de session au site " + src.Name);
			if(src.Login(client))
			{
				lstConsole.Items.Add("Session ouverte avec succes");
				DownloadConfiguration(src,client);
				DownloadProductVariantGroup(src,client);
				DownloadProductAttributGroup(src,client);
				DownloadCustomerGroups(src,client);
				DownloadQuantityDiscountGroups(src,client);
				DownloadManufacturers(src,client);
				DownloadSpecials(src,client);
				DownloadProductAttachments(src,client);
				DownloadProducts(src,client);
				DownloadArticleCartegories(src,client);
				DownloadArticles(src,client);
				DownloadFaqs(src,client);
				DownloadSlideImages(src,client);
				DownloadPolls(src,client);
				DownloadCustomers(src,client);
				DownloadOrders(src,client);
				DownloadCoupons(src,client);
				DownloadUnitClasses(src,client);
				DownloadLanguages(src,client);
				DownloadWeightClasses(src,client);
				DownloadInformations(src,client);
				DownloadDevises(src,client);
				DownloadUsers(src,client);
				DownloadCategories(src,client);
			}
			else
			{
				lstConsole.Items.Add("Impossible d'ouvrir une session, compte et/ou pass incorrect");
			}
		}
		
		private void DownloadCategories(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Categories");
			CategoryStore store = new CategoryStore(site,client);
			List<IDictionary> Categories = store.GetAllCategories();
			int i = 1;
			foreach(IDictionary Category in Categories)
			{
				lstConsole.Items.Add("Category " + i + "------------------------------");
				foreach(string key in Category.Keys)
				{
					lstConsole.Items.Add(key + " : " + Category[key]);
				}
				
				i++;
			}
		}
		
		private void DownloadUsers(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des User");
			UserStore store = new UserStore(site,client);
			List<IDictionary> Users = store.GetUsers();
			int i = 1;
			foreach(IDictionary user in Users)
			{
				lstConsole.Items.Add("User " + i + "------------------------------");
				foreach(string key in user.Keys)
				{
					if(key != "accesses")
					{
						lstConsole.Items.Add(key + " : " + user[key]);
					}
				}
				
				lstConsole.Items.Add("-----accesses------------------------------");
				foreach(string key1 in user.Keys)
				{
					if(key1 == "accesses")
					{
						List<IDictionary> accesses = (List<IDictionary>)user[key1];
						
						foreach(IDictionary access in accesses)
						{
							foreach(string cle1 in access.Keys)
							{
								if(cle1 != "children")
								{
									lstConsole.Items.Add("-----" + cle1 + " : " + access[cle1]);
								}
							}
							
							lstConsole.Items.Add("----------children ------------------------------");
							foreach(string cle2 in access.Keys)
							{								
								if(cle2 == "children")
								{
									List<IDictionary> children = (List<IDictionary>)access[cle2];
									
									foreach(IDictionary child in children)
									{
										foreach(string cle3 in child.Keys)
										{
											lstConsole.Items.Add("---------------" + cle3 + " : " + child[cle3]);
										}
										lstConsole.Items.Add("--------------------------------------");
									}
								}
							}
						}
					}
				}
				
				i++;
			}
		}

		private void DownloadDevises(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Informations");
			DeviseStore store = new DeviseStore(site,client);
			List<IDictionary> Devises = store.GetDevises();
			int i = 1;
			foreach(IDictionary Devise in Devises)
			{
				lstConsole.Items.Add("Devise " + i + "------------------------------");
				foreach(string key in Devise.Keys)
				{
					lstConsole.Items.Add(key + " : " + Devise[key]);
				}
				
				i++;
			}
		}

		private void DownloadInformations(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Informations");
			InformationStore store = new InformationStore(site,client);
			List<IDictionary> Informations = store.GetInformations();
			int i = 1;
			foreach(IDictionary Information in Informations)
			{
				lstConsole.Items.Add("Information " + i + "------------------------------");
				foreach(string key in Information.Keys)
				{
					lstConsole.Items.Add(key + " : " + Information[key]);
				}
				
				i++;
			}
		}

		private void DownloadWeightClasses(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Faqs");
			WeightClassStore store = new WeightClassStore(site,client);
			List<IDictionary> WeightClasses = store.GetWeightClasses();
			int i = 1;
			foreach(IDictionary WeightClass in WeightClasses)
			{
				lstConsole.Items.Add("WeightClass " + i + "------------------------------");
				foreach(string key in WeightClass.Keys)
				{
					if(key != "rules")
					{
						lstConsole.Items.Add(key + " : " + WeightClass[key]);
					}
				}

				lstConsole.Items.Add("-----rules " + i + "------------------------------");
				foreach(string key in WeightClass.Keys)
				{
					if(key == "rules")
					{
						List<IDictionary> rules = (List<IDictionary>)WeightClass[key];
						
						foreach(IDictionary rule in rules)
						{
							foreach(string cle1 in rule.Keys)
							{
								lstConsole.Items.Add("-----" + cle1 + " : " + rule[cle1]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				i++;
			}
		}

		private void DownloadLanguages(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Languages");
			LanguageStore store = new LanguageStore(site,client);
			List<IDictionary> Languages = store.GetLanguages();
			int i = 1;
			foreach(IDictionary Language in Languages)
			{
				lstConsole.Items.Add("Language " + i + "------------------------------");
				foreach(string key in Language.Keys)
				{
					if(key != "parent_language" && key != "translation_groups")
					{
						lstConsole.Items.Add(key + " : " + Language[key]);
					}
				}
				
				lstConsole.Items.Add("-----parent_language " + i + "------------------------------");
				foreach(string key in Language.Keys)
				{
					if(key == "parent_language")
					{
						List<IDictionary> parent_language = (List<IDictionary>)Language[key];
						
						foreach(IDictionary language in parent_language)
						{
							foreach(string cle in language.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + language[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				lstConsole.Items.Add("-----translation_groups " + i + "------------------------------");
				foreach(string key in Language.Keys)
				{
					if(key == "translation_groups")
					{
						List<IDictionary> translation_groups = (List<IDictionary>)Language[key];
						
						foreach(IDictionary translation_group in translation_groups)
						{
							foreach(string cle in translation_group.Keys)
							{
								if(cle != "translations")
								{
									lstConsole.Items.Add("-----" + cle + " : " + translation_group[cle]);
								}
							}
							foreach(string cle in translation_group.Keys)
							{
								if(cle == "translations")
								{
									List<IDictionary> translations = (List<IDictionary>)translation_group[cle];
									foreach(IDictionary translation in translations)
									{
										lstConsole.Items.Add("----------translation " + i + "------------------------------");
										foreach(string cle1 in translation.Keys)
										{
											if(key != "translations")
											{
												lstConsole.Items.Add("----------" + cle1 + " : " + translation[cle1]);
											}
										}
									}
								}
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				i++;
			}
		}

		private void DownloadUnitClasses(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des UnitClasses");
			UnitClassStore store = new UnitClassStore(site,client);
			List<IDictionary> UnitClasses = store.GetUnitClasses();
			int i = 1;
			foreach(IDictionary UnitClass in UnitClasses)
			{
				lstConsole.Items.Add("UnitClass " + i + "------------------------------");
				foreach(string key in UnitClass.Keys)
				{
					lstConsole.Items.Add(key + " : " + UnitClass[key]);
				}
				
				i++;
			}
		}

		private void DownloadCoupons(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Coupons");
			CouponStore store = new CouponStore(site,client);
			List<IDictionary> Coupons = store.GetCoupons();
			int i = 1;
			foreach(IDictionary Coupon in Coupons)
			{
				lstConsole.Items.Add("Coupon " + i + "------------------------------");
				foreach(string key in Coupon.Keys)
				{
					if(key != "categories" && key != "products")
					{
						lstConsole.Items.Add(key + " : " + Coupon[key]);
					}
				}
				
				lstConsole.Items.Add("-----categories du coupon " + i + "------------------------------");
				foreach(string key in Coupon.Keys)
				{
					if(key == "categories")
					{
						List<IDictionary> categories = (List<IDictionary>)Coupon[key];
						
						foreach(IDictionary category in categories)
						{
							foreach(string cle in category.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + category[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				lstConsole.Items.Add("-----produits du coupon " + i + "------------------------------");
				foreach(string key in Coupon.Keys)
				{
					if(key == "products")
					{
						List<IDictionary> products = (List<IDictionary>)Coupon[key];
						
						foreach(IDictionary product in products)
						{
							foreach(string cle in product.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + product[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				i++;
			}
		}

		private void DownloadOrders(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Orders");
			OrderStore store = new OrderStore(site,client);
			List<IDictionary> Orders = store.GetOrders();
			int i = 1;
			foreach(IDictionary Order in Orders)
			{
				lstConsole.Items.Add("Order " + i + "------------------------------");
				foreach(string key in Order.Keys)
				{
					if(key != "order_products" && key != "orders_status" && key != "gift_certificates")
					{
						lstConsole.Items.Add(key + " : " + Order[key]);
					}
				}
				
				lstConsole.Items.Add("-----order_products " + i + "------------------------------");
				foreach(string key in Order.Keys)
				{
					if(key == "order_products")
					{
						List<IDictionary> order_products = (List<IDictionary>)Order[key];
						
						foreach(IDictionary order_product in order_products)
						{
							foreach(string cle in order_product.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + order_product[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				lstConsole.Items.Add("-----orders_status " + i + "------------------------------");
				foreach(string key in Order.Keys)
				{
					if(key == "orders_status")
					{
						List<IDictionary> orders_status = (List<IDictionary>)Order[key];
						
						foreach(IDictionary status in orders_status)
						{
							foreach(string cle in status.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + status[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				lstConsole.Items.Add("-----gift_certificates " + i + "------------------------------");
				foreach(string key in Order.Keys)
				{
					if(key == "gift_certificates")
					{
						List<IDictionary> gift_certificates = (List<IDictionary>)Order[key];
						
						foreach(IDictionary gift_certificate in gift_certificates)
						{
							foreach(string cle in gift_certificate.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + gift_certificate[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				i++;
			}
		}

		private void DownloadCustomers(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Customers");
			CustomerStore store = new CustomerStore(site,client);
			List<IDictionary> Customers = store.GetCustomers();
			
			int i = 1;
			foreach(IDictionary Customer in Customers)
			{
				lstConsole.Items.Add("Customer " + i + "------------------------------");
				foreach(string key in Customer.Keys)
				{
					if(key != "address_books" && key != "store_credits" && key != "wishlists")
					{
						lstConsole.Items.Add(key + " : " + Customer[key]);
					}
				}
				
				i++;
			}
			
			i = 1;
			foreach(IDictionary Customer in Customers)
			{
				lstConsole.Items.Add("-----address_books du Customer " + i + "------------------------------");
				foreach(string key in Customer.Keys)
				{
					if(key == "address_books")
					{
						List<IDictionary> address_books = (List<IDictionary>)Customer[key];
						
						foreach(IDictionary address_book in address_books)
						{
							foreach(string cle in address_book.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + address_book[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				i++;
			}
			
			i = 1;
			foreach(IDictionary Customer in Customers)
			{
				lstConsole.Items.Add("-----store_credits du Customer " + i + "------------------------------");
				foreach(string key1 in Customer.Keys)
				{
					if(key1 == "store_credits")
					{
						List<IDictionary> store_credits = (List<IDictionary>)Customer[key1];
						
						foreach(IDictionary store_credit in store_credits)
						{
							foreach(string cle in store_credit.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + store_credit[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				i++;
			}
			
			i = 1;
			foreach(IDictionary Customer in Customers)
			{
				lstConsole.Items.Add("-----wishlists du Customer " + i + "------------------------------");
				foreach(string key2 in Customer.Keys)
				{
					if(key2 == "wishlists")
					{
						List<IDictionary> wishlists = (List<IDictionary>)Customer[key2];
						
						foreach(IDictionary wishlist in wishlists)
						{
							foreach(string cle in wishlist.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + wishlist[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				i++;
			}
			
		}

		private void DownloadConfiguration(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement de la Configuration");
			ConfigurationStore store = new ConfigurationStore(site,client);
			IDictionary Configuration = store.GetConfiguration();
			lstConsole.Items.Add("Configuration ------------------------------");
			foreach(string key in Configuration.Keys)
			{
				lstConsole.Items.Add(key + " : " + Configuration[key]);
			}
		}

		private void DownloadPolls(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Polls");
			PollStore store = new PollStore(site,client);
			List<IDictionary> Polls = store.GetPolls();
			int i = 1;
			foreach(IDictionary Poll in Polls)
			{
				lstConsole.Items.Add("Poll " + i + "------------------------------");
				foreach(string key in Poll.Keys)
				{
					if(key != "entries")
					{
						lstConsole.Items.Add(key + " : " + Poll[key]);
					}
				}
				
				lstConsole.Items.Add("-----Entries du Poll " + i + "------------------------------");
				foreach(string key in Poll.Keys)
				{
					if(key == "entries")
					{
						List<IDictionary> entries = (List<IDictionary>)Poll[key];
						
						foreach(IDictionary entry in entries)
						{
							foreach(string cle in entry.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + entry[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				i++;
			}
		}

		private void DownloadSlideImages(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des SlideImages");
			SlideImageStore store = new SlideImageStore(site,client);
			List<IDictionary> SlideImages = store.GetSlideImages();
			int i = 1;
			foreach(IDictionary SlideImage in SlideImages)
			{
				lstConsole.Items.Add("SlideImage " + i + "------------------------------");
				foreach(string key in SlideImage.Keys)
				{
					lstConsole.Items.Add(key + " : " + SlideImage[key]);
				}
				
				i++;
			}
		}

		private void DownloadFaqs(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Faqs");
			FaqStore store = new FaqStore(site,client);
			List<IDictionary> Faqs = store.GetFaqs();
			int i = 1;
			foreach(IDictionary Faq in Faqs)
			{
				lstConsole.Items.Add("FAQ " + i + "------------------------------");
				foreach(string key in Faq.Keys)
				{
					lstConsole.Items.Add(key + " : " + Faq[key]);
				}
				
				i++;
			}
		}

		private void DownloadArticles(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des articles");
			ArticleStore store = new ArticleStore(site,client);
			List<IDictionary> Articles = store.GetArticles();
			int i = 1;
			foreach(IDictionary Article in Articles)
			{
				lstConsole.Items.Add("Article " + i + "------------------------------");
				foreach(string key in Article.Keys)
				{
					lstConsole.Items.Add(key + " : " + Article[key]);
				}
				
				i++;
			}
		}

		private void DownloadArticleCartegories(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des categories d'article");
			ArticleCartegoryStore store = new ArticleCartegoryStore(site,client);
			List<IDictionary> ArticleCartegories = store.GetArticleCartegories();
			int i = 1;
			foreach(IDictionary ArticleCartegory in ArticleCartegories)
			{
				lstConsole.Items.Add("Category " + i + "------------------------------");
				foreach(string key in ArticleCartegory.Keys)
				{
					lstConsole.Items.Add(key + " : " + ArticleCartegory[key]);
				}
				
				i++;
			}
		}

		private void DownloadProducts(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des products");
			ProductStore store = new ProductStore(site,client);
			List<IDictionary> products = store.GetProducts();
			int i = 1;
			foreach(IDictionary product in products)
			{
				lstConsole.Items.Add("Product " + i + "------------------------------");
				foreach(string key in product.Keys)
				{
					if(key != "attributes" && key != "images" && key != "variants_products" && key != "xsell_products" && key != "products_attachments" && key != "accessories")
					{
						lstConsole.Items.Add(key + " : " + product[key]);
					}
				}
				
				lstConsole.Items.Add("-----accessories du product " + i + "------------------------------");
				foreach(string key in product.Keys)
				{
					if(key == "accessories")
					{
						List<IDictionary> accessories = (List<IDictionary>)product[key];
						
						foreach(IDictionary accessory in accessories)
						{
							foreach(string cle in accessory.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + accessory[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				lstConsole.Items.Add("-----products_attachments du product " + i + "------------------------------");
				foreach(string key in product.Keys)
				{
					if(key == "products_attachments")
					{
						List<IDictionary> products_attachments = (List<IDictionary>)product[key];
						
						foreach(IDictionary product_attachment in products_attachments)
						{
							foreach(string cle in product_attachment.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + product_attachment[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				lstConsole.Items.Add("-----xsell_products du product " + i + "------------------------------");
				foreach(string key in product.Keys)
				{
					if(key == "xsell_products")
					{
						List<IDictionary> xsell_products = (List<IDictionary>)product[key];
						
						foreach(IDictionary xsell_product in xsell_products)
						{
							foreach(string cle in xsell_product.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + xsell_product[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				lstConsole.Items.Add("-----variants_products du product " + i + "------------------------------");
				foreach(string key in product.Keys)
				{
					if(key == "variants_products")
					{
						List<IDictionary> variants_products = (List<IDictionary>)product[key];
						
						foreach(IDictionary variant_product in variants_products)
						{
							foreach(string cle in variant_product.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + variant_product[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				lstConsole.Items.Add("-----images du product " + i + "------------------------------");
				foreach(string key in product.Keys)
				{
					if(key == "images")
					{
						List<IDictionary> images = (List<IDictionary>)product[key];
						
						foreach(IDictionary image in images)
						{
							foreach(string cle in image.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + image[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}

				lstConsole.Items.Add("-----attributes du product " + i + "------------------------------");
				foreach(string key in product.Keys)
				{
					if(key == "attributes")
					{
						List<IDictionary> attributes = (List<IDictionary>)product[key];
						
						foreach(IDictionary attribute in attributes)
						{
							foreach(string cle in attribute.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + attribute[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				i++;
			}
		}

		private void DownloadProductAttachments(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des pieces jointes");
			ProductAttachmentStore store = new ProductAttachmentStore(site,client);
			List<IDictionary> productAttachments = store.GetProductAttachments();
			int i = 1;
			foreach(IDictionary productAttachment in productAttachments)
			{
				lstConsole.Items.Add("Piece jointe " + i + "------------------------------");
				foreach(string key in productAttachment.Keys)
				{
					lstConsole.Items.Add(key + " : " + productAttachment[key]);
				}
				
				i++;
			}
		}

		private void DownloadSpecials(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des offres speciales");
			SpecialStore store = new SpecialStore(site,client);
			List<IDictionary> specials = store.GetSpecials();
			int i = 1;
			foreach(IDictionary special in specials)
			{
				lstConsole.Items.Add("Offre speciale " + i + "------------------------------");
				foreach(string key in special.Keys)
				{
					lstConsole.Items.Add(key + " : " + special[key]);
				}
				
				i++;
			}
		}

		private void DownloadManufacturers(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Manufacturers");
			ManufacturerStore store = new ManufacturerStore(site,client);
			List<IDictionary> manufacturers = store.GetManufacturers();
			int i = 1;
			foreach(IDictionary manufacturer in manufacturers)
			{
				lstConsole.Items.Add("Manufacturer " + i + "------------------------------");
				foreach(string key in manufacturer.Keys)
				{
					lstConsole.Items.Add(key + " : " + manufacturer[key]);
				}
				
				i++;
			}
		}

		private void DownloadQuantityDiscountGroups(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des Quantity Discount Groups");
			QuantityDiscountGroupStore store = new QuantityDiscountGroupStore(site,client);
			List<IDictionary> quantityDiscountGroups = store.GetQuantityDiscountGroups();
			int i = 1;
			foreach(IDictionary group in quantityDiscountGroups)
			{
				lstConsole.Items.Add("Groupe " + i + "------------------------------");
				foreach(string key in group.Keys)
				{
					if(key != "entries")
					{
						lstConsole.Items.Add(key + " : " + group[key]);
					}
				}
				
				lstConsole.Items.Add("-----Entries du Groupe " + i + "------------------------------");
				foreach(string key in group.Keys)
				{
					if(key == "entries")
					{
						List<IDictionary> entries = (List<IDictionary>)group[key];
						
						foreach(IDictionary entry in entries)
						{
							foreach(string cle in entry.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + entry[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				i++;
			}
		}

		private void DownloadProductVariantGroup(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des groupes de variantes de produit");
			ProductVariantStore sync = new ProductVariantStore(site,client);
			List<IDictionary> productVariantGroups = sync.GetProductVariantGroups();
			int i = 1;
			foreach(IDictionary group in productVariantGroups)
			{
				lstConsole.Items.Add("Groupe " + i + "------------------------------");
				foreach(string key in group.Keys)
				{
					if(key != "entries")
					{
						lstConsole.Items.Add(key + " : " + group[key]);
					}
				}
				
				lstConsole.Items.Add("-----Entries du Groupe " + i + "------------------------------");
				foreach(string key in group.Keys)
				{
					if(key == "entries")
					{
						List<IDictionary> entries = (List<IDictionary>)group[key];
						
						foreach(IDictionary entry in entries)
						{
							foreach(string cle in entry.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + entry[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				i++;
			}
		}

		private void DownloadCustomerGroups(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des groupes de client");
			CustomerGroupStore store = new CustomerGroupStore(site,client);
			List<IDictionary> customerGroups = store.GetCustomerGroups();
			int i = 1;
			foreach(IDictionary group in customerGroups)
			{
				lstConsole.Items.Add("Groupe " + i + "------------------------------");
				foreach(string key in group.Keys)
				{
					lstConsole.Items.Add(key + " : " + group[key]);
				}
				
				i++;
			}
		}

		private void DownloadProductAttributGroup(Site site,HtmlWeb client)
		{
			lstConsole.Items.Add("Telechargement des groupes d'attribut de produit");
			ProductAttributStore store = new ProductAttributStore(site,client);
			List<IDictionary> productAttributGroups = store.GetProductAttributGroups();
			int i = 1;
			foreach(IDictionary group in productAttributGroups)
			{
				lstConsole.Items.Add("Groupe " + i + "------------------------------");
				foreach(string key in group.Keys)
				{
					if(key != "entries")
					{
						lstConsole.Items.Add(key + " : " + group[key]);
					}
				}
				
				lstConsole.Items.Add("-----Entries du Groupe " + i + "------------------------------");
				foreach(string key in group.Keys)
				{
					if(key == "entries")
					{
						List<IDictionary> entries = (List<IDictionary>)group[key];
						
						foreach(IDictionary entry in entries)
						{
							foreach(string cle in entry.Keys)
							{
								lstConsole.Items.Add("-----" + cle + " : " + entry[cle]);
							}
							lstConsole.Items.Add("--------------------------------------");
						}
					}
				}
				
				i++;
			}
		}
		
		void BtnNewClick(object sender, EventArgs e)
		{
			SiteConfigForm frm = new SiteConfigForm();
			frm.ShowDialog();
			LoadSites();
		}
		
		void Button2Click(object sender, EventArgs e)
		{
			SyncProfileForm frm = new SyncProfileForm();
			frm.ShowDialog();
		}
		
		void Button3Click(object sender, EventArgs e)
		{
			SyncForm syncFrm = new SyncForm();
			syncFrm.ShowDialog();
		}
	}
}
